Skip to content

Conversation

@IlyasYOY
Copy link

@IlyasYOY IlyasYOY commented Oct 27, 2025

Hey @cweill!

I’ve put together a sketch implementation that addresses the problem discussed in issue #33.

  • The core idea is implemented, but I’m aware there are some ruff‑related edge cases that still need polishing.
  • I’d really appreciate any advice or guidance you (or the community) can offer to smooth those out.

Thanks again for the thorough integration tests—they were incredibly helpful in shaping this approach! 🙏

Looking forward to your thoughts.

What this PR does

  • New PackageTest flag in Options (and related structs) to generate tests in a _test package.
  • Imports github.com/cweill/gotests/internal/gomod and uses it to resolve full import paths when PackageTest && Exported.
  • Adjusted test generation logic to propagate PackageTest through the rendering pipeline.
  • Updated render signatures and templates:
    • render.TestFunction now receives packageTest and packageName.
    • Templates (header.tmpl, function.tmpl, call.tmpl) now emit _test package names and handle qualified calls correctly.
  • Added a comprehensive gomod implementation with:
    • GetFullImportPath, findGoMod, parseModulePath.
    • Example usage in example_test.go.
    • Unit tests covering various path scenarios and edge cases.
  • Updated existing tests to cover the new PackageTest behavior and switched a ioutil.WriteFile call to the newer 0o644 octal literal.
  • Minor refactor of models.Header to include PackageTest.

Implement GetFullImportPath to resolve full Go import paths, with helper functions findGoMod and parseModulePath. Add example usage in internal/gomod/example_test.go and extensive unit tests covering various scenarios and edge cases. Include testdata for simple and nested modules.
Introduce a new PackageTest option in Options, Header, and render logic to support generating tests in a separate `_test` package. Update import handling, templates, and related tests. Add corresponding test data for the new behavior.
Removed temporary variable and console output used for debugging in `options.go`. Directly pass `b.Bytes()` to `imports.Process` and eliminate unnecessary `fmt.Println` statements, cleaning up the code without altering functionality.
Copy link
Author

@IlyasYOY IlyasYOY Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must mention that the gomod was generated by AI and reviewed by myself.

Everything else was done manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant